home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_04 / 1n04080a < prev    next >
Text File  |  1990-08-07  |  7KB  |  214 lines

  1.  
  2. Figure 7. DLGSAMPLE.C - Source file
  3. -----------------------------------
  4. /*
  5.  * DLGSAMPL.C
  6.  */
  7. #define LINT_ARGS
  8. .
  9. #include <stdio.h>
  10. #include <windows.h>
  11. #include "dlgsampl.h"
  12. .
  13. HANDLE    hInst;
  14. .
  15. long FAR PASCAL MainFormWndProc(HWND, unsigned, WORD,
  16.                                  LONG);
  17. BOOL FAR PASCAL SQLPrimerDlg(HWND, unsigned, WORD,
  18.                               LONG);
  19. .
  20. /*
  21.  * WinMain()
  22.  */
  23. int PASCAL WinMain(hInstance, hPrevInstance, CmdLine,
  24.                                    CmdShow)
  25.     HANDLE hInstance,hPrevInstance;
  26.     LPSTR CmdLine;
  27.     int CmdShow;
  28.     {
  29.     WNDCLASS WndClass;
  30.     HWND hWnd;
  31.     MSG msg;
  32. .
  33.     hInst=hInstance;
  34. .
  35.     /*
  36.      * Register Main Form Window Class
  37.      */
  38.     if (!hPrevInstance){
  39.        WNDCLASS WndClass;
  40.        WndClass.lpszClassName = (LPSTR)"dlgsampl1";
  41.        WndClass.hInstance     = hInstance;
  42.        WndClass.lpfnWndProc   = MainFormWndProc;
  43.        WndClass.style         = CS_HREDRAW | CS_VREDRAW;
  44.        WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  45.        WndClass.hIcon         = NULL;
  46.        WndClass.lpszMenuName  = "MAINMENU";
  47.        WndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  48.        WndClass.cbClsExtra    = NULL;
  49.        WndClass.cbWndExtra    = NULL;
  50.        if (!RegisterClass(&WndClass))
  51.           return(NULL);
  52.        }
  53. .
  54.     /*
  55.      * Create MainForm Window
  56.      */
  57.     hWnd = CreateWindow("dlgsampl1",
  58.                         "SQL Primer",
  59.                         WS_OVERLAPPEDWINDOW,
  60.                         0,
  61.                         0,
  62.                         CW_USEDEFAULT,
  63.                         0,
  64.                         NULL,
  65.                         NULL,
  66.                         hInstance,
  67.                         NULL);
  68.     if (!hWnd)
  69.       return (NULL);
  70.     /*
  71.      * Message Loop
  72.      */
  73.     while (GetMessage (&msg,NULL,0,0)){
  74.        TranslateMessage (&msg) ;
  75.        DispatchMessage (&msg) ;
  76.        }
  77.     return (msg.wParam);
  78.     }
  79. /*
  80.  * MainFormWndProc()
  81.  */
  82. long FAR PASCAL MainFormWndProc(hWnd, message, wParam,
  83.                                   lParam)
  84.   HWND hWnd;
  85.   unsigned message;
  86.   WORD wParam;
  87.   LONG lParam;
  88.   {
  89.   switch (message){
  90.      case WM_CREATE:
  91.           ShowWindow(hWnd,SW_SHOWNORMAL);
  92.           UpdateWindow(hWnd);
  93.           break;
  94.      case WM_COMMAND:
  95.           switch(wParam){
  96.              case IDM_SQLPRIMER:
  97.                   DoDialog(hInst,hWnd,"SQLPRIMER",
  98.                             SQLPrimerDlg);
  99.                   break;
  100.              case IDM_EXIT:
  101.                   DestroyWindow(hWnd);
  102.                   break;
  103.              }
  104.           break;
  105.      case WM_DESTROY:
  106.           PostQuitMessage(0);
  107.           break;
  108.      default:return(DefWindowProc(hWnd,message,wParam,
  109.                                    lParam));
  110.      }
  111.   return (NULL);
  112.   }
  113. /*
  114.  * DoDialog
  115.  */
  116. int DoDialog(HANDLE hInst,HWND hWnd,char *Res,FARPROC
  117.                 lpProc){
  118.    FARPROC lpfn;
  119.    BOOL ret;
  120.    lpfn = MakeProcInstance(lpProc, hInst);
  121.    ret = DialogBox(hInst,Res, hWnd, lpfn);
  122.    FreeProcInstance(lpfn);
  123.    return(ret);
  124.    }
  125. /*
  126.  * SQLPrimerDlg()
  127.  */
  128. BOOL FAR PASCAL SQLPrimerDlg(HWND hDlg,
  129.                              unsigned message,
  130.                              WORD wParam,
  131.                              LONG lParam){
  132.   static char buf[10];
  133.   switch (message){
  134.      case WM_INITDIALOG:
  135.           SendMessage(GetDlgItem(hDlg,ID_COMBO1),
  136.                       CB_ADDSTRING,
  137.                       0,
  138.                       (LONG)(LPSTR)"DML-Data Manipulation Language");
  139.           SendMessage(GetDlgItem(hDlg,ID_COMBO1),
  140.                       CB_ADDSTRING,
  141.                       0,
  142.                       (LONG)(LPSTR)"DDL-Data Definition Language");
  143.           SendMessage(GetDlgItem(hDlg,ID_COMBO1),
  144.                       CB_ADDSTRING,
  145.                       0,
  146.                       (LONG)(LPSTR)"DCL-Data Control Language");
  147.           return(FALSE);
  148.      case WM_COMMAND:
  149.           switch(wParam){
  150.              case ID_COMBO1:
  151.                   if (HIWORD(lParam)==CBN_SELCHANGE){
  152.                      GetDlgItemText(hDlg,ID_COMBO1,(LPSTR)buf,4);
  153.                      SendMessage(hDlg,WM_COMMAND,ID_POPULATE,0L);
  154.                      }
  155.                   return(FALSE);
  156.              case ID_POPULATE:
  157.                   SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  158.                               LB_RESETCONTENT,
  159.                               0,
  160.                               0L);
  161.                   if (!strnicmp(buf,"DML",3)){
  162.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  163.                                  LB_ADDSTRING,
  164.                                  0,
  165.                                  (LONG)(LPSTR)"Delete");
  166.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  167.                                  LB_ADDSTRING,
  168.                                  0,
  169.                                  (LONG)(LPSTR)"Insert");
  170.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  171.                                  LB_ADDSTRING,
  172.                                  0,
  173.                                  (LONG)(LPSTR)"Update");
  174.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  175.                                  LB_ADDSTRING,
  176.                                  0,
  177.                                  (LONG)(LPSTR)"Select");
  178.                      break;
  179.                      }
  180.                   if (!strnicmp(buf,"DDL",3)){
  181.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  182.                                  LB_ADDSTRING,
  183.                                  0,
  184.                                  (LONG)(LPSTR)"Create");
  185.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  186.                                  LB_ADDSTRING,
  187.                                  0,
  188.                                  (LONG)(LPSTR)"Drop");
  189.                      break;
  190.                      }
  191.                   if (!strnicmp(buf,"DCL",3)){
  192.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  193.                                  LB_ADDSTRING,
  194.                                  0,
  195.                                  (LONG)(LPSTR)"Grant");
  196.                      SendMessage(GetDlgItem(hDlg,ID_LISTBOX),
  197.                                  LB_ADDSTRING,
  198.                                  0,
  199.                                  (LONG)(LPSTR)"Revoke");
  200.                      break;
  201.                      }
  202.                   break;
  203.              case ID_OK:
  204.                   EndDialog(hDlg,TRUE);
  205.                   break;
  206.              default:return(FALSE);
  207.              }
  208.           break;
  209.      default:return(FALSE);
  210.      }
  211.   return(TRUE);
  212.   }
  213.  
  214.